<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title></title>
<%@ include file="/WEB-INF/views/include/easyui.jsp"%>
</head>
<body style="font-family: '微软雅黑'">
	<div id="tb" style="padding: 5px; height: auto">
		<div>

			<a href="#" class="easyui-linkbutton" plain="true" iconCls="icon-add"
				onclick="add();">添加</a> <span
				class="toolbar-item dialog-tool-separator"></span> <a href="#"
				class="easyui-linkbutton" plain="true" iconCls="icon-remove"
				onclick="del()">删除</a> <span
				class="toolbar-item dialog-tool-separator"></span> <a href="#"
				class="easyui-linkbutton" plain="true" iconCls="icon-edit"
				onclick="upd()">生成表单</a> <span
				class="toolbar-item dialog-tool-separator"></span>
				<a href="#"
				class="easyui-linkbutton" plain="true" iconCls="icon-reload"
				onclick="ref()">同步数据库</a> 
		</div>
	</div>
	<table id="dg"></table>

	<div id="dlg"></div>
	<div id="icon_dlg"></div>

	<script type="text/javascript">
var dg;
var d;
$(function(){   
	dg=$('#dg').datagrid({    
	method: "get",
    url:'<%=path%>/generator/datagrid', 
    fit : true,
	fitColumns : true,
	border : false,
	//idField : 'id',
	striped:true,
	pagination:true,
	rownumbers:true,
	pageNumber:1,
	pageSize : 20,
	pageList : [ 10, 20, 30, 40, 50 ],
	singleSelect:true,
	columns:[[
					{field:'gtableName',title:'表名',width:100}
					,
					{field:'gtableComment',title:'表备注',width:100}
					,
					{field:'id',title:'操作',width:100,formatter: function(value,row,index){
						 
						return '<a href="javascript:copy(\''+row.id+'\')">复制表</a>   <a target="_blank" href="<%=path%>/generator/auto/toList?id='+row.id+'">预览</a>';
					}}
					
		]],
    headerContextMenu: [
        {
            text: "冻结该列", disabled: function (e, field) { return dg.datagrid("getColumnFields", true).contains(field); },
            handler: function (e, field) { dg.datagrid("freezeColumn", field); }
        },
        {
            text: "取消冻结该列", disabled: function (e, field) { return dg.datagrid("getColumnFields", false).contains(field); },
            handler: function (e, field) { dg.datagrid("unfreezeColumn", field); }
        }
    ],
    enableHeaderClickMenu: true,
    enableHeaderContextMenu: true,
    enableRowContextMenu: false,
    toolbar:'#tb'
	});
});




var msg="${result}";
if(typeof(msg)!='undefined'&&msg!='') {
	layer.msg(msg);
}
	

//弹窗增加
function add() {
	layer.msg("暂不支持在线创建表....");
}
function ref(){
	$.ajax({url:"<%=path%>/generator/synchronization",async:false,success:function(){dg.datagrid('load')}});
}

function copy(id){
	
	$.ajax({url:"<%=path%>/generator/copy?id="+id,async:false,success:function(){dg.datagrid('load')}});

}
//删除
function del(){
	var row = dg.treegrid('getSelected');
	if(rowIsNull(row)) return;
	parent.$.messager.confirm('提示', '删除后无法恢复您确定要删除？', function(data){
		if (data){
			$.ajax({
				type:'get',
				url:"<%=path%>/generator/del?id="+row.id,
				success: function(data){
					if(successTip(data,dg)){
			    		dg.treegrid('reload');
			    	}
				}
			});
		} 
	});

}

//修改
function upd(){
	var row = dg.treegrid('getSelected');
	if(rowIsNull(row)) return;
	d=$("#dlg").dialog({   
	    title: '生成表单',    
	    width: 1000,    
	    height: 500,    
	    href:'<%=path%>/generator/tableCol?id=' + row.id,
				maximizable : true,
				modal : true,
				buttons : [ {
					text : '确认',
					handler : function() {
						//alert("123");
						$("#mainform").submit();
					}
				}, {
					text : '取消',
					handler : function() {
						d.panel('close');
					}
				} ]
			});

		}
	</script>
</body>
</html>